package com.modules.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.modules.entity.User;
import com.modules.entity.UserDao;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private UserDao userDao;
    

    @RequestMapping(value = "/login",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Map<String,Object> login(@RequestBody User user) {
        Map<String,Object> resultMap = new HashMap<>(3);
        try {
        	User ru = userDao.findByUserNameAndPassword(user.getUserName(), user.getPassword());
        	if(ru!=null) {
	            resultMap.put("user",ru);
	            resultMap.put("status", "0");
	            resultMap.put("msg","ok");
        	}else {
        		resultMap.put("user",null);
	            resultMap.put("status", "-1");
	            resultMap.put("msg","用户密码错误");
        	}
        }catch (Exception e) {
            resultMap.put("user",null);
            resultMap.put("status", "-2");
            resultMap.put("msg","登录失败！");
        }
        return resultMap;
    }
}
